<!-- 业务付款列表 -->
<template>
  <div class="payment-list">
    <div ref="dgtools" class="filter-container">
      <div class="dgts-row">
        <b class="tr-it">订单总价：{{ priceAll }}元</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">派单总价：{{ totalPrice }}元</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">已付款：{{ alPayPrice }}元</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">应付款：{{ shouldPayPrice }}元</b>
      </div>

      <div class="dgts-fm">
        <el-select
          v-model="dg.ps.serviceMan"
          clearable
          filterable
          :disabled="serviceManList.length === 0"
          :placeholder="'业务员'"
          style="width: 100px">
          <el-option
            v-for="it in serviceManList"
            :key="it.baseUserId.uname"
            :label="it.baseUserId.realName"
            :value="it.baseUserId.uname">
            <span>{{it.baseUserId.realName}}</span>
            <span>{{it.baseUserId.phone}}</span>
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.timeType"
          placeholder="时间类型"
          style="width: 100px">
          <el-option label="用车时间" value="1"></el-option>
          <el-option label="下单时间" value="2"></el-option>
        </el-select>

        <el-date-picker
          v-model="dg.ps.sedate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 210px"
          value-format="yyyy-MM-dd">
        </el-date-picker>

        <el-select
          v-model="dg.ps.compositor"
          placeholder="排序"
          style="width: 80px">
          <el-option label="升序" value="ASC"></el-option>
          <el-option label="降序" value="DESC"></el-option>
        </el-select>

        <el-input
          style="width: 160px"
          placeholder="订单号"
          clearable
          v-model="dg.ps.orderNum"
        />

        <el-input
          style="width: 160px"
          placeholder="行程详情"
          v-model="dg.ps.routeDetail"
        />

        <el-select
          v-model="dg.ps.payStatus"
          placeholder="订单支付状态"
          clearable
          style="width: 120px">
          <el-option label="未付款" value="UNPAID"></el-option>
          <el-option label="申请成功" value="APPLY_SUCCESS"></el-option>
          <el-option label="已付定金" value="DEPOSIT_PAID"></el-option>
          <el-option label="全款已付" value="FULL_PAID"></el-option>
        </el-select>

        <el-input
          style="width: 90px"
          placeholder="车牌号"
          clearable
          v-model="dg.ps.plateNum"
        />

        <el-input
          style="width: 120px"
          clearable
          placeholder="查询驾驶员姓名/手机号"
          v-model="dg.ps.driver"
        />

        <el-select
          v-model="dg.ps.customId"
          clearable filterable
          :remote="true"
          :remote-method="queryCusPageList"
          :placeholder="'用车单位'"
          style="width: 240px">
          <el-option
            v-for="it in clientList"
            :key="it.baseUserId.uname"
            :label="it.baseUserId.realName + '【' + it.baseUserId.phone + '】【' + it.unitName + '】'"
            :value="it.id"
            @click.native="selectCus(it.baseUserId.uname)">
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.dutyMan"
          clearable
          filterable
          :disabled="clientList.length === 0"
          style="width: 160px"
          placeholder="联系人">
          <el-option
            v-for="it in dutyManList"
            :key="it.uname"
            :label="it.realName"
            :value="it.uname">
          </el-option>
        </el-select>

        <el-select
          style="width: 100px"
          v-model="dg.ps.payLock"
          placeholder="付款锁定">
          <el-option label="未锁定" value="UNLOCK"></el-option>
          <el-option label="已锁定" value="LOCKED"></el-option>
        </el-select>

        <el-select
          v-model="dg.ps.suppCusId"
          clearable filterable
          :placeholder="'供车单位'"
          style="width: 240px">
          <el-option
            v-for="it in partunitList"
            :key="it.baseUserId.uname"
            :label="it.baseUserId.realName + '【' +it.baseUserId.phone +'】【' +it.unitName +'】'"
            :value="it.id"
            @click.native="selectOfflineSuppCar(it.baseUserId.uname)">
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.suppMan"
          clearable
          filterable
          placeholder="供车人"
          style="width: 160px">
          <el-option
            v-for="it in ownerPersonList"
            :key="it.uname"
            :label="it.realName + '' + it.phone"
            :value="it.uname">
          </el-option>
        </el-select>

        <el-input
          style="width: 150px"
          placeholder="操作号"
          v-model="dg.ps.operMark"
        />

        <el-button 
          type="primary" 
          icon="el-icon-search" 
          @click="getDgList">
          搜索
        </el-button>

        <div>
          <el-button 
            type="primary" 
            icon="el-icon-s-check" 
            @click="setAddPaymentMd({state: true})">
            申请付款
          </el-button>

          <el-button 
            type="primary" 
            icon="el-icon-s-release" 
            @click="cancelApply">
            撤销付款申请
          </el-button>

          <el-button 
            type="primary" 
            icon="el-icon-s-release" 
            @click="cancelLock">
            取消锁定
          </el-button>

          <el-button
            type="primary"
            icon="el-icon-document-copy"
            @click="setBackPaymentMd({state: true})">
            平账
          </el-button>

          <el-button 
            type="primary" 
            icon="el-icon-close" 
            @click="setCancelBackPaymentMd({state: true})">
            撤销平账
          </el-button>

          <el-button 
            type="primary" 
            icon="el-icon-bottom" 
            @click="exportExcel">
            导出
          </el-button>
        </div>
      </div>

      <TableSelfSet
        v-if="dg.columns.length > 0"
        :tbTitle="'业务付款'"
        :dgName="dg.dgName"
        :tbId="dg.tbName"
        :srcCols="dg.srcCols"
        :columns="dg.columns"
        @saveSet="saveTbSet"
      />
    </div>
    <el-table
      :ref="dg.tbName"
      :data="dg.list"
      row-key="id"
      :height="bodyHeight"
      border fit
      :row-class-name="rowClassName"
      @header-dragend="dragHeader"
      @selection-change="selRowChange">
      <el-table-column 
        fixed="left" 
        type="index" 
        label="编号"
        align="center" 
        :resizable="false" 
        width="40">
      </el-table-column>
      <el-table-column 
        fixed="left" 
        type="selection" 
        align="center" 
        :resizable="false" 
        width="40">
      </el-table-column>
      <el-table-column 
        v-for="(col, index) in dg.columns" 
        :key="index"
        :class-name="dg.dgName"
        :prop="col.field"
        :label="col.label"
        :width="col.width">
        <template slot-scope="{ row }">
          <template v-if="col.field == 'disCarId'">
            {{ (row.disCarId && row.disCarId.plateNum) || "&#45;&#45;" }}
          </template>

          <template v-else-if="col.field == 'disDriver'">
            {{ (row.disCarId && row.disCarId.outDriverInfo) || '' }}
          </template>

          <template v-else-if="col.field == 'suppCompanyCus'">
            {{(row.disCarId && row.disCarId.suppCompanyCus) ? row.disCarId.suppCompanyCus.unitName : ''}}
          </template>

          <template v-else-if="col.field == 'suppDutyBaseUser'">
            {{(row.disCarId && row.disCarId.suppDutyBaseUser) ? row.disCarId.suppDutyBaseUser.realName+'-'+row.disCarId.suppDutyBaseUser.phone : ''}}
          </template>

          <template v-else-if="col.field == 'sdate'">
            {{row.stime | time('yyyy-MM-dd')}}
          </template>

          <template v-else-if="col.field == 'stime'">
            {{row.stime | time('HH:mm')}}
          </template>

          <template v-else-if="col.field == 'edate'">
            {{row.etime | time('yyyy-MM-dd')}}
          </template>

          <template v-else-if="col.field == 'etime'">
            {{row.etime | time('HH:mm')}}
          </template>

          <template v-else-if="col.field == 'status'">
            <b v-for="it in orderStateArr.filter(o => o.id == row.status)" 
              :key="it.id" 
              :class="it.color">
              {{row.status == it.id ? it.name : ''}}
            </b>
          </template>

          <template v-else-if="col.field == 'payStatus'">
            <b v-for="it in payStatusArr.filter(o => o.id == row.payStatus)" 
              :key="it.id" 
              :class="it.color">
              {{row.payStatus == it.id ? it.name : ''}}
            </b>
          </template>

          <template v-else-if="col.field == 'payLock'">
            <b v-for="it in lockStaeArr.filter(o => o.id == row.payLock)" 
              :key="it.id" 
              :class="it.color">
              {{row.payLock == it.id ? it.name : ''}}
            </b>
          </template>

          <template v-else-if="col.field == 'serviceType'">
            <b v-for="it in serviceTypeArr.filter(o => o.id == row.serviceType)" 
              :key="it.id" 
              :class="it.color">
              {{row.serviceType == it.id ? it.name : ''}}
            </b>
          </template>

          <template v-else-if="col.field == 'routeDetail'">
            <span v-html="row.routeDetail.replace(/@/g, '<br />')"></span>
          </template>

          <template v-else-if="col.field == 'useCarCompany'">
            {{row.carOrderBase.customId.unitName}}
          </template>

          <template v-else-if="col.field == 'useCarDutyUser'">
            {{row.carOrderBase.dutyBaseUser.realName}}-{{row.carOrderBase.dutyBaseUser.phone}}
          </template>

          <template v-else-if="col.field == 'serviceMan'">
            {{row.carOrderBase.serviceMan.split('-')[1]}}-{{row.carOrderBase.serviceMan.split('-')[2]}}
          </template>
          
          <template v-else-if="col.field == 'operNote'">
            <span v-if="row.operNote" v-html="row.operNote.replace(/\(/g, '<br />').replace(/\)/g, '；<br />').replace(/&nbsp;,/g, '<br />')"></span>
          </template>

          <template v-else>{{ getColVal(row, col.field) }}</template>
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      v-show="dg.total > 0"
      :total="dg.total"
      :page.sync="dg.ps.page"
      :limit.sync="dg.ps.rows"
      @pagination="getDgList"
    />

    <AddPayment
      v-if="addPaymentMd.state"
      :myData="addPaymentMd"
      @myClick="setAddPaymentMd"
      @reloadDg="getDgList"
    />

    <PayBackPayment
      v-if="backPaymentMd.state"
      :myData="backPaymentMd"
      @myClick="setBackPaymentMd"
      @reloadDg="getDgList"
    />

    <CancelPayBackPayment
      v-if="cancelBackPaymentMd.state"
      :myData="cancelBackPaymentMd"
      @myClick="setCancelBackPaymentMd"
      @reloadDg="getDgList"
    />

  </div>
</template>

<script>
import DataGridResize from "@/views/mixins/DataGridResize";
import DataGridBase from "@/views/mixins/DataGridBase";
import elDragDialog from "@/directive/el-drag-dialog";
import TableSelfSet from "@/components/TableSelfSet";
import Pagination from "@/components/Pagination";
import { exportExcel } from "@/utils/exportFile";

import * as commonSer from "@/api/services/common.service";
import * as orderSer from "@/api/services/order.service";

import AddPayment from "./add-payment";
import PayBackPayment from "./pay-back-payment";
import CancelPayBackPayment from "./cancel-pay-back-payment";

export default {
  name: "PaymentList",
  mixins: [DataGridResize, DataGridBase],
  directives: { elDragDialog },
  components: { TableSelfSet, Pagination, AddPayment, PayBackPayment, CancelPayBackPayment },
  data() {
    let cols = [
      { label: "订单号", field: "orderNum", width: 140 },
      { label: "供车方单位", field: "suppCompanyCus", width: 150 },
      { label: "供车方负责人", field: "suppDutyBaseUser", width: 150 },
      { label: "开始日期", field: "sdate", width: 80 },
      { label: "开始时间", field: "stime", width: 70 },
      { label: "结束日期", field: "edate", width: 80 },
      { label: "结束时间", field: "etime", width: 70 },
      { label: "派单车辆", field: "disCarId", width: 80 },
      { label: "派单驾驶员", field: "disDriver", width: 150 },
      { label: "所需座位数", field: "needSeats", width: 80 },
      { label: "订单状态", field: "status", width: 100 },
      { label: "订单支付状态", field: "payStatus", width: 100 },
      { label: "订单运价", field: "price", width: 100 },
      { label: "付款锁定", field: "payLock", width: 120 },
      { label: "派单价格", field: "disPrice", width: 120 },
      { label: "已付金额", field: "alPayPrice", width: 100 },
      { label: "旅网金额", field: "travelPrepayPrice", width: 100 },
      { label: "自网金额", field: "selfPrepayPrice", width: 100 },
      { label: "提醒师傅现收(元)", field: "remDriverCharge", width: 140 },
      { label: "其他费用", field: "otherPrice", width: 100 },
      { label: "应付余额", field: "dealPrice", width: 100 },
      { label: "订单业务类型", field: "serviceType", width: 120 },
      { label: "行程简称", field: "routeSimpleName", width: 100 },
      { label: "行程详情", field: "routeDetail", width: 300 },
      { label: "用车方单位", field: "useCarCompany", width: 150 },
      { label: "用车方负责人", field: "useCarDutyUser", width: 150 },
      { label: "业务员", field: "serviceMan", width: 150 },
      { label: "业务员备注", field: "cusNote", width: 200 },
      { label: "驾驶员备注", field: "driverNote", width: 200 },
      { label: "客户备注", field: "serviceNote", width: 200 },
      { label: "财务备注", field: "operNote", width: 230 },
      { label: "操作编号", field: "operMark", width: 120 },
    ];

    return {
      dg: {
        dgName: "dg",
        tbName: "paymentListTb",
        srcCols: cols,
        columns: [],
        selRows: [],
        total: 0,
        list: [],
        ps: {
          page: 1, rows: 100,
          // 传值：0
          useSelf: 0,
          // 订单号
          orderNum: "", 
          // 搜索时间类型
          timeType: "1", 
          // 时间顺序
          compositor: "ASC", 
          // 客户（用车方）
          customId: "", 
          // 驾驶员手机号/姓名（外调驾驶员）
          driver: "", 
          // 用车方负责人
          dutyMan: "", 
          // 起止日期
          sedate: "",
          // 开始时间
          startTime: "", 
          // 结束时间
          endTime: "", 
          // 订单支付状态
          payStatus: "",
          // 车牌号 
          plateNum: "", 
          // 业务员
          serviceMan: "", 
          // 供车方id
          suppCusId: "", 
          // 供车方负责人
          suppMan: "", 
          // 确认付款价格
          payLock: "",  
          // 行程详情
          routeDetail: "", 
          // 操作编号
          operMark: "", 
        },
      },

      // 申请付款-弹框
      addPaymentMd: {state: false},
      // 平账-弹框
      backPaymentMd: {state: false},
      // 撤销平账-弹框
      cancelBackPaymentMd: {state: false},

      // 订单支付状态
      payStatusArr: [
        { id: "UNPAID", name: "未付款", color: 'c-red' },
        { id: "DEPOSIT_PAID", name: "已付定金", color: 'c-yellow' },
        { id: "FULL_PAID", name: "全款已付", color: 'c-black' },
        { id: "APPLY_SUCCESS", name: "申请成功", color: 'c-green' },
      ],
      // 订单状态
      orderStateArr : [
        { id: "", name: "订单状态（全部）" },
        { id: "NOT_DIS_CAR", name: "未派车" },
        { id: "JL_NOT_CONFIRM", name: "已预派" },
        { id: "DRIVER_NOT_CONFIRM", name: "师傅未确认" },
        { id: "DRIVER_CONFIRMED", name: "师傅已确认" },
        { id: "AL_TRAVEL", name: "已出行" },
        { id: "COMPLETED", name: "已完成" },
      ],
      // 业务员类型
      serviceTypeArr : [
        { id: "COUNTY_SER", name: "县际业务" },
        { id: "CITY_SER", name: "市际业务" },
        { id: "PROVINCE_SER", name: "省际业务" },
      ],
      // 锁定状态
      lockStaeArr: [
        { id: 'UNLOCK', name: "未锁定", color: 'c-green'}, 
        {id: 'LOCKED', name: "已锁定", color: 'c-red' }
      ],

      // 业务员-选择数据
      serviceManList: [], 
      // 客户-选择数据
      clientList: [], 
      // 联系人选择数据
      dutyManList: [], 
      // 供车方单位-选择数据
      partunitList: [], 
      // 供车方负责人-选择数据
      ownerPersonList: [],

    };
  },
  computed: {
    // 订单总价
    priceAll() {
      const that = this, rows = that.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += parseFloat(rows[i].price);
      }
      return sum.toFixed(2);
    },
    // 派单总价
    totalPrice() {
      const that = this, rows = that.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += parseFloat(rows[i].disPrice);
      }
      return sum.toFixed(2);
    },
    // 已付款金额
    alPayPrice() {
      const that = this, rows = that.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        let item = rows[i];
        sum += parseFloat(item.alPayPrice);
      }
      return sum.toFixed(2);
    },
    // 应付款金额
    shouldPayPrice() {
      const that = this, rows = that.getSeledRows();
      
      // 判断是否位同一用户
      let isUnique = true, cusId = null;
      for(let i = 0; i < rows.length; i++){
        let it = rows[i];
        if(i == 0) {
          cusId = it.carOrderBase.customId.unitName;
        }else if(cusId != it.carOrderBase.customId.unitName){
          isUnique = false;
          break;
        }
      }

      // 统计应付
      let sum = 0;
      if (!isUnique) {// 非同一客户：只能累计派车价格大于已付的【应付】
        for (let i = 0; i < rows.length; i++) {
          let item = rows[i];
          if(item.disPrice > item.alPayPrice){
            sum += parseFloat(item.disPrice) - parseFloat(item.alPayPrice);
          }
        }
      }else{// 全部是同一客户：则要累加所有订单的【应付】 
        for (let i = 0; i < rows.length; i++) {
          let item = rows[i];
          sum += parseFloat(item.disPrice) - parseFloat(item.alPayPrice);
        }
      }

      return sum.toFixed(2);
    },
  },
  created() {
    this.initTbSetData(this.dg.dgName);
    this.getDgList();

    this.init();
  },
  methods: {
    init() {
      // 获取-业务员-选择数据
      commonSer.getStaffCombo({ staffState: "NORMAL,TRY" }).then((res) => {
        this.serviceManList = res?.data || [];
      });

      // 获取-供车方单位-选择数据
      commonSer.getCompanyCusList({ cusType: "CARTEAM" }).then((res) => {
        this.partunitList = res?.data || [];
      });
    },
    /**
     * 获取-单位客户-选择列表（用于下拉框）
     * @param find 客户手机号/用户名/姓名
     */
    queryCusPageList(find){
      commonSer.queryComboCusPageList({find: find}).then(res=> {
        this.clientList = res?.data || [];
      });
    },

    // // 获取-订单支付状态-描述
    // getPayState(state) {
    //   let result = this.payStatusArr.find(it => it.id === state);
    //   return result;
    // },
    // // 获取-订单状态-描述
    // getState(state) {
    //   let result = this.orderStateArr.find(it => it.id == state);
    //   return result?.name || "--";
    // },
    // // 获取-订单业务类型-描述
    // getServericType(state) {
    //   let result = this.serviceTypeArr.find(it => it.id === state);
    //   return result.name || "--";
    // },
    // // 获取-订单锁定状态-描述
    // getLock(data) {
    //   let state = { UNLOCK: "未锁定", LOCKED: "已锁定" };
    //   return state[data] || "--";
    // },
    // 获取-表格数据
    getDgList() {
      const that = this, ps = that.U.scopy(that.dg.ps);

      ps.startTime = ps.sedate && ps.sedate.length == 2 ? ps.sedate[0] : '';
      ps.endTime = ps.sedate && ps.sedate.length == 2 ? ps.sedate[1] : '';
      delete ps.sedate;

      orderSer.getCarOrderList(ps).then((res) => {
        if (res.code === 1) {
          let list = res.data;
          list.forEach((it) => { it.dgName = this.dg.dgName; });

          // 应付余额=派单总价-已付金额
          that.dg.list = list.map((item) => {
            item.dealPrice = parseFloat(item.disPrice) - parseFloat(item.alPayPrice);
            return item;
          });
          that.dg.total = res.count;
        }
      });
    },
    
    // 选择-客户-获取联系人
    selectCus(uname) {
      this.dg.ps.dutyMan = "";
      orderSer.geDutysByCuList({ cusUname: uname }).then((res) => {
        this.dutyManList = res.data;
      });
    },

    // 选择-供车单位-获取供车人
    selectOfflineSuppCar(uname) {
      this.dg.ps.suppMan = "";
      orderSer.geDutysByCuList({ cusUname: uname }).then((res) => {
        if(res.code == 1){
          this.ownerPersonList = res.data;
          if(this.ownerPersonList.length == 1) this.dg.ps.suppMan = this.ownerPersonList[0].uname; 
        }
      });
    },

    // 显示/隐藏-申请付款-弹框
    setAddPaymentMd(e) {
      const that = this, U = that.U, md = that.addPaymentMd, rows = that.getSeledRows();
      
      if(!e.state){
        md.list = null;
        md.state = false;
      }else{
        if (rows.length === 0) {
          U.qerror("请至少选择一条订单进行付款");
        }else{
          let isObj = rows.find(it => it.payStatus != 'UNPAID');
          if(isObj) {
            U.qerror(`所选第${isObj.index+1}行数据不是【未付款】，不能申请`);
          }else{
            md.list = rows;
            md.state = true;
          }
        }
      }
    },
    // 取消付款锁定
    cancelLock() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length !== 1) {
        U.qerror("请选择一个订单进行取消付款锁定");
      }else{
        let row = rows[0];
        if(!row.payLock || row.payLock === "UNLOCK"){
          U.qerror("该订单未被锁定，请重新选择！");
        }else{
          orderSer.cancelConfirmPayment({ id: row.id }).then((res) => {
            if (res.code !== 1) {
              U.qerror(res.msg);
            }else{
              U.qsuccess(res.msg);

              that.getDgList();
            }
          });
        }
      }
    },
    // 撤销付款申请
    cancelApply() {
      const that = this, U = that.U, rows = that.getSeledRows();

      // 只有申请成功的才能进行撤销付款申请 APPLY_SUCCESS
      if (rows.length === 0) {
        U.qerror("请至少选择一条订单进行撤销");
      }else{
        // 撤销编号
        let result = rows.filter(it => it.payStatus === "APPLY_SUCCESS");
        if (result && result.length === 0) {
          U.qerror("请选择【申请成功】的订单进行撤销");
        }else{
          U.qconfim('您确定撤销所选数据？').then(r => {
            if(r){
              let ids = result.map(it => it.id).join(',');
              orderSer.cancelServicePay({ ids: ids }).then((res) => {
                if (res.code !== 1) {
                  U.qerror(res.msg);
                }else{
                  U.qsuccess(res.msg);

                  that.getDgList();
                }
              });
            }
          });
        }
      }
    },
    // 显示/隐藏-平账-弹框
    setBackPaymentMd(e) {
      const that = this, U = that.U, md = that.backPaymentMd, rows = that.getSeledRows();
      
      if(!e.state){
        md.data = null;
        md.state = false;
      }else{
        if (rows.length < 2) {
          U.qerror("请至少选择2条数据进行平账");
        }else{
          // 判断是否位同一用户
          let isUnique = true, cusId = null;
          for(let i = 0; i < rows.length; i++){
            let it = rows[i];
            if(i == 0) {
              cusId = it.disCarId.carCompanyUname;
            }else if(cusId != it.disCarId.carCompanyUname){
              isUnique = false;
              break;
            }
          }
          if (!isUnique) {
            U.qerror("请选同一用户进行平账");
          }else{
            // 必须有正数和负数
            let priceArr = rows.map(it => (it.disPrice - it.alPayPrice));
            let isMinus = priceArr.some(it => it < 0);
            let isPositive = priceArr.some(it => it >= 0);
            if (!isMinus || !isPositive) {
              U.qerror("必须存在多付金额");
            }else{
              md.data = rows;
              md.state = true;
            }
          }
        }
      }
    },
    // 显示/隐藏-撤销平账-弹框
    setCancelBackPaymentMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows(), md = that.cancelBackPaymentMd;

      if(!e.state){
        md.state = false;
        md.obj = null;
      }else{
        if(rows.length == 0){
          U.qerror(`请至少选择一个订单数据`);
        }else{
          md.list = rows;
          md.state = true;
        }
      }
    },

    // 导出excel
    exportExcel() {
      const that = this, U = that.U, ps = that.U.scopy(that.dg.ps);

      ps.startTime = ps.sedate && ps.sedate.length == 2 ? ps.sedate[0] : '';
      ps.endTime = ps.sedate && ps.sedate.length == 2 ? ps.sedate[1] : '';
      delete ps.sedate;

      ps.rows = that.dg.total;
      orderSer.exportService(ps).then((res) => {
        if (res.code !== 1) {
          U.qerror(res.msg);
        }else{
          U.qsuccess('导出成功，请稍等...');

          exportExcel({
            filename: "业务付款",
            data: res.data,
            enumData: {
              orderNum: "订单号",
              suppCompanyUser: "供车方单位",
              suppDutyBaseUser: "供车方负责人",
              sdate: "开始日期",
              stime: "开始时间",
              edate: "结束日期",
              etime: "结束时间",
              plateNum: "派单车辆",
              outDriverInfo: "派单驾驶员",
              needSeats: "所需座位数",
              status: "订单状态",
              payStatus: "订单支付状态",
              price: "订单运价",
              payLock: "付款锁定",
              disPrice: "派单价格",
              alPayPrice: "已付金额",
              travelPrepayPrice: "旅网金额",
              selfPrepayPrice: "自网金额",
              remDriverCharge: "提醒师傅现收(元)",
              otherPrice: "其他费用",
              shouldPayPrice: '应付余额',
              serviceType: "订单业务类型",
              routeSimpleName: "行程简称",
              routeDetail: "行程详情",
              customId: "用车方单位",
              dutyBaseUser: "用车方负责人",
              serviceMan: "业务员",
              serviceNote: "业务员备注",
              driverNote: "驾驶员备注",
              cusNote: "客户备注",
              operNote: "财务备注",
              operMark: "操作编号",
            },
          });
        }
      });
    },

  },
};
</script>